import java.util.Vector;


class P10591_39643 {

	static String readLn() {
		String newLine = System.getProperty("line.separator");
		StringBuffer buffer = new StringBuffer();
		int car = -1;
		try {
			car = System.in.read();
			while ((car > 0) && (car != newLine.charAt(0))) {
				buffer.append((char) car);
				car = System.in.read();
			}
			if (car == newLine.charAt(0))
				System.in.skip(newLine.length() - 1);
		} catch (java.io.IOException e) {
			return (null);
		}
		if ((car < 0) && (buffer.length() == 0))
			return (null);
		return (buffer.toString()).trim();
	}

	
	public static void main(String[] args) {
		int cases = Integer.parseInt(readLn());
		
		for (int k = 0; k < cases; k++) {
			System.out.print("Case #"+ (k+1) + ": ");
			process(Integer.parseInt(readLn()));
		}
		
	}


	private static void process(int i) {
		System.out.print(i + " is a");
		if (isHappy(i)) 
			System.out.println(" Happy number.");
		else System.out.println("n Unhappy number.");
		
	}


	private static boolean isHappy(int i) {
		Vector v = new Vector();
		
		Integer inte = new Integer(i);
		v.addElement(inte);
		
		while (true) {
			
			inte = sum(inte);
			
			if (inte.intValue() == 1) return true;
			if (v.contains(inte)) return false;

//			System.out.println(inte);
			
			v.addElement(inte);
			
		}
		
		// TODO Auto-generated method stub
//		return false;
	}


	private static Integer sum(Integer inte) {
		
		int i = 0;
		String s = inte.toString();
		
		for (int k = 0; k < s.length(); k++) {
			i += Math.pow((s.charAt(k) - '0'), 2);
		}
		
		return new Integer(i);
	}
	
}
